// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

#nullable restore

using Elastic.Clients.Elasticsearch.Fluent;
using Elastic.Clients.Elasticsearch.Serialization;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Elastic.Clients.Elasticsearch;

public sealed partial class ScriptSort
{
	[JsonInclude, JsonPropertyName("mode")]
	public Elastic.Clients.Elasticsearch.SortMode? Mode { get; set; }
	[JsonInclude, JsonPropertyName("nested")]
	public Elastic.Clients.Elasticsearch.NestedSortValue? Nested { get; set; }
	[JsonInclude, JsonPropertyName("order")]
	public Elastic.Clients.Elasticsearch.SortOrder? Order { get; set; }
	[JsonInclude, JsonPropertyName("script")]
	public Elastic.Clients.Elasticsearch.Script Script { get; set; }
	[JsonInclude, JsonPropertyName("type")]
	public Elastic.Clients.Elasticsearch.ScriptSortType? Type { get; set; }

	public static implicit operator Elastic.Clients.Elasticsearch.SortOptions(ScriptSort scriptSort) => Elastic.Clients.Elasticsearch.SortOptions.Script(scriptSort);
}

public sealed partial class ScriptSortDescriptor<TDocument> : SerializableDescriptor<ScriptSortDescriptor<TDocument>>
{
	internal ScriptSortDescriptor(Action<ScriptSortDescriptor<TDocument>> configure) => configure.Invoke(this);

	public ScriptSortDescriptor() : base()
	{
	}

	private Elastic.Clients.Elasticsearch.SortMode? ModeValue { get; set; }
	private Elastic.Clients.Elasticsearch.NestedSortValue? NestedValue { get; set; }
	private Elastic.Clients.Elasticsearch.NestedSortValueDescriptor<TDocument> NestedDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.NestedSortValueDescriptor<TDocument>> NestedDescriptorAction { get; set; }
	private Elastic.Clients.Elasticsearch.SortOrder? OrderValue { get; set; }
	private Elastic.Clients.Elasticsearch.Script ScriptValue { get; set; }
	private Elastic.Clients.Elasticsearch.ScriptSortType? TypeValue { get; set; }

	public ScriptSortDescriptor<TDocument> Mode(Elastic.Clients.Elasticsearch.SortMode? mode)
	{
		ModeValue = mode;
		return Self;
	}

	public ScriptSortDescriptor<TDocument> Nested(Elastic.Clients.Elasticsearch.NestedSortValue? nested)
	{
		NestedDescriptor = null;
		NestedDescriptorAction = null;
		NestedValue = nested;
		return Self;
	}

	public ScriptSortDescriptor<TDocument> Nested(Elastic.Clients.Elasticsearch.NestedSortValueDescriptor<TDocument> descriptor)
	{
		NestedValue = null;
		NestedDescriptorAction = null;
		NestedDescriptor = descriptor;
		return Self;
	}

	public ScriptSortDescriptor<TDocument> Nested(Action<Elastic.Clients.Elasticsearch.NestedSortValueDescriptor<TDocument>> configure)
	{
		NestedValue = null;
		NestedDescriptor = null;
		NestedDescriptorAction = configure;
		return Self;
	}

	public ScriptSortDescriptor<TDocument> Order(Elastic.Clients.Elasticsearch.SortOrder? order)
	{
		OrderValue = order;
		return Self;
	}

	public ScriptSortDescriptor<TDocument> Script(Elastic.Clients.Elasticsearch.Script script)
	{
		ScriptValue = script;
		return Self;
	}

	public ScriptSortDescriptor<TDocument> Type(Elastic.Clients.Elasticsearch.ScriptSortType? type)
	{
		TypeValue = type;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (ModeValue is not null)
		{
			writer.WritePropertyName("mode");
			JsonSerializer.Serialize(writer, ModeValue, options);
		}

		if (NestedDescriptor is not null)
		{
			writer.WritePropertyName("nested");
			JsonSerializer.Serialize(writer, NestedDescriptor, options);
		}
		else if (NestedDescriptorAction is not null)
		{
			writer.WritePropertyName("nested");
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.NestedSortValueDescriptor<TDocument>(NestedDescriptorAction), options);
		}
		else if (NestedValue is not null)
		{
			writer.WritePropertyName("nested");
			JsonSerializer.Serialize(writer, NestedValue, options);
		}

		if (OrderValue is not null)
		{
			writer.WritePropertyName("order");
			JsonSerializer.Serialize(writer, OrderValue, options);
		}

		writer.WritePropertyName("script");
		JsonSerializer.Serialize(writer, ScriptValue, options);
		if (TypeValue is not null)
		{
			writer.WritePropertyName("type");
			JsonSerializer.Serialize(writer, TypeValue, options);
		}

		writer.WriteEndObject();
	}
}

public sealed partial class ScriptSortDescriptor : SerializableDescriptor<ScriptSortDescriptor>
{
	internal ScriptSortDescriptor(Action<ScriptSortDescriptor> configure) => configure.Invoke(this);

	public ScriptSortDescriptor() : base()
	{
	}

	private Elastic.Clients.Elasticsearch.SortMode? ModeValue { get; set; }
	private Elastic.Clients.Elasticsearch.NestedSortValue? NestedValue { get; set; }
	private Elastic.Clients.Elasticsearch.NestedSortValueDescriptor NestedDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.NestedSortValueDescriptor> NestedDescriptorAction { get; set; }
	private Elastic.Clients.Elasticsearch.SortOrder? OrderValue { get; set; }
	private Elastic.Clients.Elasticsearch.Script ScriptValue { get; set; }
	private Elastic.Clients.Elasticsearch.ScriptSortType? TypeValue { get; set; }

	public ScriptSortDescriptor Mode(Elastic.Clients.Elasticsearch.SortMode? mode)
	{
		ModeValue = mode;
		return Self;
	}

	public ScriptSortDescriptor Nested(Elastic.Clients.Elasticsearch.NestedSortValue? nested)
	{
		NestedDescriptor = null;
		NestedDescriptorAction = null;
		NestedValue = nested;
		return Self;
	}

	public ScriptSortDescriptor Nested(Elastic.Clients.Elasticsearch.NestedSortValueDescriptor descriptor)
	{
		NestedValue = null;
		NestedDescriptorAction = null;
		NestedDescriptor = descriptor;
		return Self;
	}

	public ScriptSortDescriptor Nested(Action<Elastic.Clients.Elasticsearch.NestedSortValueDescriptor> configure)
	{
		NestedValue = null;
		NestedDescriptor = null;
		NestedDescriptorAction = configure;
		return Self;
	}

	public ScriptSortDescriptor Order(Elastic.Clients.Elasticsearch.SortOrder? order)
	{
		OrderValue = order;
		return Self;
	}

	public ScriptSortDescriptor Script(Elastic.Clients.Elasticsearch.Script script)
	{
		ScriptValue = script;
		return Self;
	}

	public ScriptSortDescriptor Type(Elastic.Clients.Elasticsearch.ScriptSortType? type)
	{
		TypeValue = type;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (ModeValue is not null)
		{
			writer.WritePropertyName("mode");
			JsonSerializer.Serialize(writer, ModeValue, options);
		}

		if (NestedDescriptor is not null)
		{
			writer.WritePropertyName("nested");
			JsonSerializer.Serialize(writer, NestedDescriptor, options);
		}
		else if (NestedDescriptorAction is not null)
		{
			writer.WritePropertyName("nested");
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.NestedSortValueDescriptor(NestedDescriptorAction), options);
		}
		else if (NestedValue is not null)
		{
			writer.WritePropertyName("nested");
			JsonSerializer.Serialize(writer, NestedValue, options);
		}

		if (OrderValue is not null)
		{
			writer.WritePropertyName("order");
			JsonSerializer.Serialize(writer, OrderValue, options);
		}

		writer.WritePropertyName("script");
		JsonSerializer.Serialize(writer, ScriptValue, options);
		if (TypeValue is not null)
		{
			writer.WritePropertyName("type");
			JsonSerializer.Serialize(writer, TypeValue, options);
		}

		writer.WriteEndObject();
	}
}